﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Documents;
using UIWindows.Models;
using UIWindows.Tools.Helper;
using UIWindows.UserControls;

namespace UIWindows.GlobalStatics
{
    [Attributes.Singleton]
    public class LogStatic
    {
        public List<Log4NetModel> LNModels { get; set; }
        public AsyncObservableCollection<RunMessageModel> LogList { get; set; }
        public AsyncObservableCollection<MesLogModel> MesLog { get; set; }
        public AsyncObservableCollection<RunMessageModel> OperationLog { get; set; }
        public LogStatic()
        {
            LogList = new AsyncObservableCollection<RunMessageModel>();
            MesLog = new AsyncObservableCollection<MesLogModel>();
            OperationLog = new AsyncObservableCollection<RunMessageModel>();
            if (!File.Exists(GlobalStatic.Log4NetPath))
            {
                //新建log4net文件
                LNModels = new List<Log4NetModel>() {
                   new Log4NetModel(){
                       LoggerName = "message",
                       DatePattern = "yyyy-MM-dd-HH\".txt\"",
                       SavePath = ".\\logs\\RunLog\\",
                       ConversionPattern = "%date{HH:mm:ss fff}$%-5level$%message$%newline",
                   },
                   new Log4NetModel(){
                       LoggerName = "operation",
                       DatePattern = "yyyy-MM-dd\".txt\"",
                       SavePath = ".\\logs\\OperationLog\\",
                       ConversionPattern = "%date{HH:mm:ss fff}$%-5level$%message$%newline",
                   },
                   new Log4NetModel(){
                       LoggerName = "plc_alarm",
                       DatePattern = "yyyy-MM-dd\".txt\"",
                       SavePath = ".\\logs\\PLCAlarm\\",
                       ConversionPattern = "%date{HH:mm:ss fff}$%-5level$%message$%newline",
                   },
                     #region MES接口日志
                   new Log4NetModel()
                   {
                       LoggerName = "OeeDataInterface",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\OEE数据收集接口\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "OeeWarningInterface",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\报警原因及时间上报接口\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "ProduceOpenAddInterface",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\产品结果数据收集接口单条\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "ProduceOpenBatchAddInterface",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\产品结果数据收集接口批量\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "GetByProductCodeInterface",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\工单获取接口\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "FrockChangeInterface",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\工装夹具更换上传接口\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "FrockLifeInterface",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\工装夹具寿命上传接口\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "UploadParamInterface",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\开机上传参数接口\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "OeeCapacityInterface",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\设备产能上报接口\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "AccountInterface",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\设备上位机账号登录接口\\",
                       ConversionPattern = "%message %newline",
                   },
                    new Log4NetModel()
                   {
                       LoggerName = "OeeStatusInterface",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\设备状态上报接口\\",
                       ConversionPattern = "%message %newline",
                   },
                     new Log4NetModel()
                   {
                       LoggerName = "ChangeParamInterface",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\修改参数上传接口\\",
                       ConversionPattern = "%message %newline",
                   },
                     new Log4NetModel()
                   {
                       LoggerName = "MaterialInInterface",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\原材料上料接口\\",
                       ConversionPattern = "%message %newline",
                   },
                     new Log4NetModel()
                   {
                       LoggerName = "MaterialOutInterface",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\原材料卸料接口\\",
                       ConversionPattern = "%message %newline",
                   },
                    new Log4NetModel()
                   {
                       LoggerName = "PreventionCheckInterface",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\在制品投料防呆校验接口\\",
                       ConversionPattern = "%message %newline",
                   },
                    new Log4NetModel()
                   {
                       LoggerName = "MqttHelper",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\过程参数\\",
                       ConversionPattern = "%message %newline",
                   },

                   #endregion
                };
                File.WriteAllText(".\\log4net.config", Log4NetHelper.WriteLog4NetXml(LNModels));
            }
            else
            {
                LNModels = Log4NetHelper.ReadLog4NetConfig(GlobalStatic.Log4NetPath);
            }
            _ = log4net.Config.XmlConfigurator.Configure(new FileInfo(GlobalStatic.Log4NetPath));
        }
    }
}
